﻿using System;
using fastCSharp;
using System.Reflection;

namespace diantou.web.ajax.comment
{
    /// <summary>
    /// 评论操作
    /// </summary>
    abstract class comment<callType, commentType> : userHandle<callType>
        where callType : comment<callType, commentType>
        where commentType : diantou.dataModel.comment
    {
        /// <summary>
        /// 添加评论
        /// </summary>
        /// <param name="value"></param>
        /// <param name="onReturn"></param>
        [fastCSharp.code.cSharp.ajax]
        public virtual void Append(commentType value, Action<fastCSharp.net.returnValue<int>> onReturn)
        {
            value.UserId = currentUser.Id;
            append(value, onReturn);
        }
        /// <summary>
        /// 删除评论
        /// </summary>
        /// <param name="id"></param>
        /// <param name="onReturn"></param>
        [fastCSharp.code.cSharp.ajax]
        public virtual void Delete(int id, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            delete(id, currentUser.Id, onReturn);
        }

        /// <summary>
        /// 添加评论委托
        /// </summary>
        private static readonly Action<commentType, Action<fastCSharp.net.returnValue<int>>> append;
        /// <summary>
        /// 删除评论委托
        /// </summary>
        private static readonly Action<int, int, Action<fastCSharp.net.returnValue<bool>>> delete;
        static comment()
        {
            Type type = typeof(commentType);
            type = type.Assembly.GetType("diantou.dataAccess.tcpCall+" + type.Name);
            append = (Action<commentType, Action<fastCSharp.net.returnValue<int>>>)Delegate.CreateDelegate(typeof(Action<commentType, Action<fastCSharp.net.returnValue<int>>>), type.GetMethod("append", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(commentType), typeof(Action<fastCSharp.net.returnValue<int>>) }, null));
            delete = (Action<int, int, Action<fastCSharp.net.returnValue<bool>>>)Delegate.CreateDelegate(typeof(Action<int, int, Action<fastCSharp.net.returnValue<bool>>>), type.GetMethod("delete", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(int), typeof(int), typeof(Action<fastCSharp.net.returnValue<bool>>) }, null));
        }
    }
}
